﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKArchUtils.Utils;

namespace YJKRevitParapet.ParapetSearch
{
	public class AngleComparerByNode : IComparer<Pole2D>
	{
		public AngleComparerByNode(XYZ ptCurNode, double referenceStartAngle)
		{
			this.m_ptCurNode = ptCurNode;
			this.m_ReferenceStartAngle = referenceStartAngle;
		}

		public int Compare(Pole2D lhv, Pole2D rhv)
		{
			double num = 0.0;
			double num2 = 0.0;
			lhv.GetAngle(this.m_ptCurNode, ref num);
			num = Geometry.BetweenTheAngles(this.m_ReferenceStartAngle, num, true);
			rhv.GetAngle(this.m_ptCurNode, ref num2);
			num2 = Geometry.BetweenTheAngles(this.m_ReferenceStartAngle, num2, true);
			if (Geometry.IsEqual(num, num2))
			{
				double val = 0.0;
				double val2 = 0.0;
				lhv.GetWinding(this.m_ptCurNode, ref val);
				rhv.GetWinding(this.m_ptCurNode, ref val2);
				if (Geometry.IsEqual(val, val2))
				{
					return 0;
				}
				if (Geometry.LessThan(val, val2))
				{
					return -1;
				}
				return 1;
			}
			else
			{
				if (num < num2)
				{
					return -1;
				}
				return 1;
			}
		}

		private XYZ m_ptCurNode;

		private double m_ReferenceStartAngle;
	}
}
